using System;
using System.Collections.Generic;
using System.Text;
using System.Transactions;
using NUnit.Framework;

namespace Hermes.Framework.Test
{
    [TestFixture]
    public abstract class CommitRollbackTest
    {
        [SetUp]
        public virtual void SetUp()
        {
        }

        [TearDown]
        public virtual void TearDown()
        {
        }

        protected abstract void Operation();

        protected abstract bool VerifyCommitOperation();

        protected abstract bool VerifyRollbackOperation();

        [Test]
        public void TestCommit()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                Operation();
            }
            Assert.IsTrue(VerifyCommitOperation());
        }

        [Test]
        public void TestRollback()
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    Operation();
                    throw new Exception();
                }
            }
            catch
            {
            }
            Assert.IsTrue(VerifyRollbackOperation());
        }
    }
}
